<?php
/**
 * Created by PhpStorm.
 * User: zhuanggit
 * Date: 2019/2/28
 * Time: 14:53
 */
namespace App\Observers;

use App\Models\Grade;
use Illuminate\Support\Facades\DB;

class GradeObserver
{
    public function updated(Grade $grade)
    {
        $temp=$grade->pro1+$grade->pro2+$grade->pro3+$grade->pro4+$grade->pro5+$grade->pro6+$grade->pro7;
        DB::table('grades')->where('id', $grade->id)->update(['sum'=>$temp]);
        if($grade->pro4!=0&&$grade->pro5!=0&&$grade->pro6!=0){
            DB::table('grades')->where('id', $grade->id)->update(['state'=>1]);
    }
    if($grade->pro1!=0&&$grade->pro2!=0&&$grade->pro3!=0){
            if($grade->pro4!=0&&$grade->pro5!=0&&$grade->pro6!=0){
                DB::table('grades')->where('id', $grade->id)->update(['state'=>2]);
            }else{
                DB::table('grades')->where('id', $grade->id)->update(['state'=>1]);
            }
        }
    }
}
